package com.socket.server;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

import com.socket.client.Request;

/**
 * Get client request,and put the request to a queue,
 * if client status is error return exception immediately.
 * @author luoweiyi
 *
 */
public class PushRequestThread extends Thread{
	
	private Socket socket;
	
	public PushRequestThread(Socket socket){
		this.socket = socket;
	}
	
	public void run(){
		ObjectInputStream dis = null;
		try {
			dis = new ObjectInputStream(socket.getInputStream());
			//read client status
			char status = dis.readChar();
			switch(status){
			case 's': 
				Request clientRequest = (Request)dis.readObject();
				RequestQueue.getInstance().setRequest(socket,clientRequest.getServer(),clientRequest.getMethodName(),clientRequest.getParams(),clientRequest.getReturnType());
				break;
			case 'f':
				
			}
		
			
		}catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
